<?php
/**
 * Field handler to provide race icons
 */
class mewdkp_handler_field_content_icon extends views_handler_field {
	function render($values) {
    if($this->aliases['field_mewdkp_icon_value']){
      if(isset($values->{$this->view->field['field_mewdkp_wowhead_value']->aliases['field_mewdkp_wowhead_value']}) && $values->{$this->view->field['field_mewdkp_wowhead_value']->aliases['field_mewdkp_wowhead_value']} != ''){
        $icon_link = '<a href="'. $values->{$this->view->field['field_mewdkp_wowhead_value']->aliases['field_mewdkp_wowhead_value']} .'" target="_blank"></a>';
      }
			$output = '<div class="wowhead-icon-medium" style="background-image: url(http://static.wowhead.com/images/icons/medium/'. strtolower($values->{$this->aliases['field_mewdkp_icon_value']}) .'.jpg)">';
			$output .= '<div class="border">'. $icon_link .'</div></div>';
      return $output;
    }
    
		if ($values->node_type == 'mewdkp_item'){
			$field = 'nid';
		} else {
			$field = 'node_node_data_field_mewdkp_item_nid';
		}
		$item = node_load($values->$field);
		if ($item->type == 'mewdkp_item'){
			$icon = strtolower($item->field_mewdkp_icon[0]['value']);		
			$output = '<div class="wowhead-icon-medium" style="background-image: url(http://static.wowhead.com/images/icons/medium/' . $icon . '.jpg)">';
			$output .= '<div class="border"><a href="' . $item->field_mewdkp_wowhead[0]['value'] . '" target="_blank"></a></div></div>';
		}
		return $output;
	}
}